package com.sg.service.biz.rbff.impl;

import com.sg.common.util.CommonFunctionHelper;
import com.sg.common.util.RedisUtil;
import com.sg.dto.biz.rbff.req.*;
import com.sg.dto.biz.rbff.res.*;
import com.sg.dto.integration.component.LoopSetResourceFileComReqDto;
import com.sg.dto.integration.component.LoopSetResourceFileComRespDto;
import com.sg.dto.integration.component.QueryStorageTemporaryCredentialsDetailComReqDto;
import com.sg.dto.integration.component.QueryStorageTemporaryCredentialsDetailComRespDto;
import com.sg.service.biz.rbff.OssService;
import com.wicket.okrcomponent.integration.OssService;
import com.wicket.okrcomponent.integration.ResourceFileService;
import com.sg.common.exception.Assert;
import org.apache.skywalking.apm.toolkit.trace.Tag;
import org.apache.skywalking.apm.toolkit.trace.Tags;
import org.apache.skywalking.apm.toolkit.trace.Trace;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author ：
 * @version 1.0
 * @date ：
 */
@Service
public class OssServiceImpl implements OssService {

    @Resource
    private RedisUtil redisUtil;
    @Resource
    com.sg.service.biz.component.OssService fwCompOssClient;
    @Resource
    com.sg.service.biz.component.ResourceFileService fwCompResourceFileClient;

    /**
     * B8查询存储临时访问令牌[10412]
     * gen by moon at 12/7/2024, 9:30:26 PM
     */
    @Trace(operationName = "B8查询存储临时访问令牌")
    @Tags({@Tag(key = "参数", value = "arg[0]"),
            @Tag(key = "返回值", value = "returnedObj")})
    @Override
    public BffQueryObjectStorageTemporaryCredentialsDetailRespDto queryObjectStorageTemporaryCredentialsDetail(BffQueryObjectStorageTemporaryCredentialsDetailReqDto reqDto) {


        LoopSetResourceFileComRespDto loopSetResourceFileComRespDto_1 = null;
        QueryStorageTemporaryCredentialsDetailComRespDto queryStorageTemporaryCredentialsDetailComRespDto_1 = null;
//步骤0: D2循环生成资源文件相对路径并缓存相对路径(公共) - loopSetResourceFileCom
        LoopSetResourceFileComRespDto loopSetResourceFileComRespDto = null;
        LoopSetResourceFileComReqDto loopSetResourceFileComReqDto = new LoopSetResourceFileComReqDto();
        loopSetResourceFileComReqDto.setSpaceId(CommonFunctionHelper.getBaseInfoFromLocal().getSpecSpaceId());//CURRENT_SPACEID//sourceId:2031588_1
        loopSetResourceFileComReqDto.setUserId(CommonFunctionHelper.getBaseInfoFromLocal().getSpecUserId());//CURRENT_USERID//sourceId:2031589_1
        if (reqDto != null) {
            loopSetResourceFileComReqDto.setPlatformOrTenantDoc(reqDto.getPlatformOrTenantDoc());//SimpleFieldAssign//sourceId:2031584_1
            loopSetResourceFileComReqDto.setDocUseType(reqDto.getDocUseType());//SimpleFieldAssign//sourceId:2031587_1
            loopSetResourceFileComReqDto.setResourceFileList(reqDto.getResourceFileList());//list-field-assign//sourceId:2031597_1
        }

        /*D2循环生成资源文件相对路径并缓存相对路径(公共)[10413]   */
        Assert.isNull(loopSetResourceFileComReqDto.getPlatformOrTenantDoc(), "B8查询存储临时访问令牌-D2循环生成资源文件相对路径并缓存相对路径(公共)-平台或租户文档不能为空", false);
        Assert.isNull(loopSetResourceFileComReqDto.getDocUseType(), "B8查询存储临时访问令牌-D2循环生成资源文件相对路径并缓存相对路径(公共)-文档用途类型不能为空", false);
        Assert.isNull(loopSetResourceFileComReqDto.getSpaceId(), "B8查询存储临时访问令牌-D2循环生成资源文件相对路径并缓存相对路径(公共)-空间ID不能为空", false);
        Assert.isNull(loopSetResourceFileComReqDto.getUserId(), "B8查询存储临时访问令牌-D2循环生成资源文件相对路径并缓存相对路径(公共)-个人账号不能为空", false);
        loopSetResourceFileComRespDto = fwCompResourceFileClient.loopSetResourceFileCom(loopSetResourceFileComReqDto).getData()/*vcase invoke 跨dubbo调用;*/;


        loopSetResourceFileComRespDto_1 = loopSetResourceFileComRespDto;

//步骤1: D2查询对象存储临时令牌详情(公共) - queryStorageTemporaryCredentialsDetailCom
        QueryStorageTemporaryCredentialsDetailComRespDto queryStorageTemporaryCredentialsDetailComRespDto = null;
        if (loopSetResourceFileComRespDto != null) {
            QueryStorageTemporaryCredentialsDetailComReqDto queryStorageTemporaryCredentialsDetailComReqDto = new QueryStorageTemporaryCredentialsDetailComReqDto();
            queryStorageTemporaryCredentialsDetailComReqDto.setOriginalRoleMemberId(CommonFunctionHelper.getBaseInfoFromLocal().getSpecOriginalRoleMemberId());//CURRENT_ORIGINAL_ROLE_MEMBERID//sourceId:2031218_1
            if (loopSetResourceFileComRespDto != null) {
                queryStorageTemporaryCredentialsDetailComReqDto.setResourceFileList(loopSetResourceFileComRespDto.getResourceFileList());//list-field-assign//sourceId:2033555_1
            }

            /*D2查询对象存储临时令牌详情(公共)[10409]   */
            Assert.isNull(queryStorageTemporaryCredentialsDetailComReqDto.getOriginalRoleMemberId(), "B8查询存储临时访问令牌-D2查询对象存储临时令牌详情(公共)-身份人员ID不能为空", false);
            queryStorageTemporaryCredentialsDetailComRespDto = fwCompOssClient.queryStorageTemporaryCredentialsDetailCom(queryStorageTemporaryCredentialsDetailComReqDto).getData()/*vcase invoke 跨dubbo调用;*/;


            queryStorageTemporaryCredentialsDetailComRespDto_1 = queryStorageTemporaryCredentialsDetailComRespDto;
        }

        BffQueryObjectStorageTemporaryCredentialsDetailRespDto retData = new BffQueryObjectStorageTemporaryCredentialsDetailRespDto();
        if (queryStorageTemporaryCredentialsDetailComRespDto_1 != null) {
            retData.setEndPoint(queryStorageTemporaryCredentialsDetailComRespDto_1.getEndPoint());//SimpleFieldAssign//sourceId:2031233_1
            retData.setReviewUrl(queryStorageTemporaryCredentialsDetailComRespDto_1.getReviewUrl());//SimpleFieldAssign//sourceId:2031234_1
            retData.setBucketName(queryStorageTemporaryCredentialsDetailComRespDto_1.getBucketName());//SimpleFieldAssign//sourceId:2031235_1
            retData.setAliyunTemporaryIdentityKey(queryStorageTemporaryCredentialsDetailComRespDto_1.getAliyunTemporaryIdentityKey());//SimpleFieldAssign//sourceId:2031236_1
            retData.setAliyunTemporaryIdentitySec(queryStorageTemporaryCredentialsDetailComRespDto_1.getAliyunTemporaryIdentitySec());//SimpleFieldAssign//sourceId:2031237_1
            retData.setAliyunTemporaryIdentityToken(queryStorageTemporaryCredentialsDetailComRespDto_1.getAliyunTemporaryIdentityToken());//SimpleFieldAssign//sourceId:2031238_1
            retData.setAliyunUploadAuthorizationPolicy(queryStorageTemporaryCredentialsDetailComRespDto_1.getAliyunUploadAuthorizationPolicy());//SimpleFieldAssign//sourceId:2031239_1
            retData.setAliyunUploadSignature(queryStorageTemporaryCredentialsDetailComRespDto_1.getAliyunUploadSignature());//SimpleFieldAssign//sourceId:2031240_1
            retData.setObjectStorageTemporaryCredentialsList(queryStorageTemporaryCredentialsDetailComRespDto_1.getObjectStorageTemporaryCredentialsList());//list-field-assign//sourceId:2033565_1
        }
        if (loopSetResourceFileComRespDto_1 != null) {
            retData.setResourceFileList(loopSetResourceFileComRespDto_1.getResourceFileList());//list-field-assign//sourceId:2031599_1
        }


        return retData;
    }
    //
}
